package mercurius.fitness.client.ui.menu.items;

import java.util.Vector;

import net.pleso.framework.client.ui.custom.CustomFormWindow;
import net.pleso.framework.client.ui.custom.CustomRBWindow;
import mercurius.fitness.client.Fitness;
import mercurius.fitness.client.locale.Locale;
import mercurius.fitness.client.rb.measurement.MeasurementsRB;
import mercurius.fitness.client.rb.measurement.forms.AddMeasurementsForm;
import mercurius.fitness.client.ui.IFrame;
import mercurius.fitness.client.util.Entry;
import mercurius.fitness.client.util.HTTPUtil;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.MenuBar;

public class MeasurementsMenu extends MenuBar  {
	
	public MeasurementsMenu() {
		super(true);
		MenuBar graphsubmenu = new MenuBar(true);
		
		addItem(Locale.constants().measurement(),new Command() {

			public void execute() {
				new CustomRBWindow(new MeasurementsRB()).show();
			}
			
		});
		
		addItem(Locale.constants().add_measurement(),new Command() {

			public void execute() {
				new CustomFormWindow(null,new AddMeasurementsForm()).show();
			}
			
		});
		
		addItem("Graphs",graphsubmenu);
		
		graphsubmenu.addItem("Weight Graph",new Command() {
			public void execute() {
				showRemoteSWFFrame("Weight Graph","showweight");
			}
		});
		
		graphsubmenu.addItem("Lean Muscle Graph",new Command() {
			public void execute() {
				showRemoteSWFFrame("Lean Muscle Graph","showlean");
			}
		});
		
		graphsubmenu.addItem("Fat Percent Graph",new Command() {
			public void execute() {
				showRemoteSWFFrame("Fat Percent Graph","showfatpercentage");
			}
		});
		
		graphsubmenu.addItem("Show Fat Mass",new Command() {
			public void execute() {
				showRemoteSWFFrame("Show Fat Mass","showfatmass");
			}
		});
		
		
		graphsubmenu.addItem("BMI Graph",new Command() {
			public void execute() {
				showRemoteSWFFrame("BMI Graph","showbmi");
			}
		});

		graphsubmenu.addItem("BMR Graph",new Command() {
			public void execute() {
				showRemoteSWFFrame("BMR Graph", "showbmr");
			}
		});
		
		graphsubmenu.addItem("Resting Pulse Graph",new Command() {
			public void execute() {
				showRemoteSWFFrame("Resting Pulse Graph", "showrestingpulse");
			}
		});
		
	}
	
	private void showRemoteSWFFrame(String caption,String type) {
		Vector v = new Vector();
		//v.add(new Entry("module","true"));
		v.add(new Entry("fulldisplay","true"));
		v.add(new Entry(type,"true"));
		v.add(new Entry("action","viewMeasurementGraph"));

		if(Fitness.get().getFeedKey().length() > 0) {
			v.add(new Entry("feedkey",Fitness.get().getFeedKey()));
		}
		
		if(!type.equals("showweight")) {
			v.add(new Entry("showweight","false"));
		}
		
		if(!type.equals("showlean")) {
			v.add(new Entry("showlean","false"));
		}
		
		if(!type.equals("showfatpercentage")) {
			v.add(new Entry("showfatpercentage","false"));
		}
		
		if(!type.equals("showfatmass")) {
			v.add(new Entry("showfatmass","false"));
		}
		
		if(!type.equals("showbmi")) {
			v.add(new Entry("showbmi","false"));
		}
		
		if(!type.equals("showbmr")) {
			v.add(new Entry("showbmr","false"));
		}
		
		if(!type.equals("showrestingpulse")) {
			v.add(new Entry("showrestingpulse","false"));
		}
		
		new IFrame(caption, HTTPUtil.Entries(v)).show();
	}
}